//
//  YJNavigationController.swift
//  微博
//
//  Created by YJW on 16/8/4.
//  Copyright © 2016年 yijiang. All rights reserved.
//

import UIKit

class YJNavigationController: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        navigationBar.isHidden = true
    }

    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        
        if childViewControllers.count > 0 {
            
            viewController.hidesBottomBarWhenPushed = true
            
            if let vc = viewController as? YJBaseViewController{
                
                var leftName = "返回"
                
                if childViewControllers.count == 1{
                    leftName = childViewControllers.first?.title ?? "返回"
                }
                vc.navigItem.leftBarButtonItem = UIBarButtonItem(name: leftName, target: self, action: #selector(popToBack),isBack:true)
            }
        }
        
        super.pushViewController(viewController, animated: true)
    }

    @objc private func popToBack() {
        popViewController(animated: true)
    }
}
